package com.Dao;

import com.Objects.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class UserDao extends DaoBase {

    public User getUser(String username, String password) {
        User result = null;

        try {
            String cmd = "select * from users where username = ? and `password` = ?";
            PreparedStatement preparedStatement = getConnection().prepareStatement(cmd);
            preparedStatement.setString(1, username);
            preparedStatement.setString(2, password);
            ResultSet resultSet = preparedStatement.executeQuery();
            if (resultSet.next()) {
                result = new User();
                result.setUserName(resultSet.getString("username"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }
}
